﻿namespace FSChart

open Builder
open System.Drawing

type Gallery =
    static member Area (?Title, ?Face, ?TextSz, ?Legend, ?TypeX, ?TitleX, ?LabelsX, ?GridX, ?TitleY, ?LabelsY, ?GridY) =
        let aTitle   = defaultArg Title   ""
        let aTitleX  = defaultArg TitleX  ""
        let aTitleY  = defaultArg TitleY  ""
        let aFace    = defaultArg Face    "Arial"
        let aTextSz  = defaultArg TextSz  8
        let aLegend  = defaultArg Legend  false
        let aTypeX   = defaultArg TypeX   XFloat
        let aLabelsX = defaultArg LabelsX true
        let aGridX   = defaultArg GridX   true
        let aLabelsY = defaultArg LabelsY true
        let aGridY   = defaultArg GridY   true
        
        let fontSmall  = (aFace, float32 aTextSz       , FontStyle.Regular)
        let fontMedium = (aFace, float32 aTextSz + 1.0f, FontStyle.Regular)
        let fontLarge  = (aFace, float32 aTextSz * 1.5f, FontStyle.Regular)
        
        let grid g = if g then grid ( dash gainsboro 1 ) else id
        let labels l = if l then labels ( font fontSmall ) else ticks off

        let ax = axis |> title ( font fontMedium )
        
        let axx =
            ax
            |> title ( text aTitleX )
            |> labels aLabelsX |> grid aGridX
            |> match aTypeX with
                | XFloat  -> linearI 2.0
                | XDate   -> timeX 6 >> margin on
                | XString -> margin on
        
        let axy =
            ax
            |> title ( text aTitleY )
            |> labels aLabelsY |> grid aGridY
            |> linear 2.0
        
        AreaDef.Create aTypeX
        |> backColor aliceBlue
        |> title ( text aTitle >> font fontLarge >> transparent )
        |> axisX ( setAs axx ) |> axisY ( setAs axy )
        |> ( if aLegend then legend ( font fontMedium >> transparent ) else id )

